home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_m_p / pcpwhost.zip / HOST1C.COM / SUBS.WAS < prev   
Text File  |  1992-09-01  |  61KB  |  1,514 lines

  1. ;Host Mode v1.00c file - Do not compile!
  2.  
  3. ;***********************************************************************
  4. ;*                                                                     *   
  5. ;* SUBS.WAS                                                            *
  6. ;* Copyright (C) 1992 Datastorm Technologies, Inc.                     *     
  7. ;* All rights reserverd.                                               * 
  8. ;*                                                                     * 
  9. ;* Purpose: Contains most of the lower level com and file I/O          *
  10. ;*          routines for Host Mode.                                    *
  11. ;*                                                                     * 
  12. ;***********************************************************************
  13.  
  14. ;***********************************************************************
  15. ;*                                                                     *
  16. ;*  WARNING!!!!                                                        *
  17. ;*                                                                     *
  18. ;*  Do not modify this script file unless you have a good under-       *
  19. ;*  standing of the Windows ASPECT language.  If you do modify this    *
  20. ;*  script, PLEASE MAKE A BACKUP before doing so.                      *
  21. ;*                                                                     *
  22. ;***********************************************************************
  23.  
  24. ;***********************************************************************
  25. ;*                                                                     *
  26. ;* HOSTSETUP                                                           *
  27. ;*                                                                     *
  28. ;* The procedure opens the HOST.PRM file and reads in variables.       *
  29. ;* Also sets up the paths for the mail files.                          *
  30. ;*                                                                     *
  31. ;* Calls: HOSTMSGBOX,   CHECKMENU                                      *
  32. ;*                                                                     *
  33. ;* Called by: MAIN                                                     *
  34. ;*                                                                     *
  35. ;* Modifies globals: sysop, local_logon, parmfile, hdrfile, msgfile,   *
  36. ;*                   logfile, usrfile, welcome_msg, upload_path,       *
  37. ;*                   dnload_path, new_usr_leve, connect_type,          *
  38. ;*                   system_type, goodbye_option, old_menu, new_menu   *
  39. ;*                                                                     *
  40. ;***********************************************************************
  41. proc HostSetup
  42.     
  43.    sysop=0
  44.    local_logon=0
  45.  
  46.    set aspect spawn on
  47.  
  48.    fetch aspect scriptpath parmfile
  49.    addfilename parmfile HOSTPRMFILE
  50.         
  51.    fetch aspect scriptpath hdrfile
  52.    addfilename hdrfile HOSTHDRFILE
  53.     
  54.    fetch aspect scriptpath msgfile
  55.    addfilename msgfile HOSTMSGFILE
  56.     
  57.    fetch aspect scriptpath logfile
  58.    addfilename logfile HOSTLOGFILE
  59.  
  60.    fetch aspect scriptpath usrfile
  61.    addfilename usrfile HOSTUSRFILE
  62.  
  63.    fetch aspect scriptpath newsfile
  64.    addfilename newsfile HOSTNWSFILE
  65.  
  66.    fetch aspect scriptpath nufile
  67.    addfilename nufile HOSTNUFILE
  68.  
  69.    fetch aspect scriptpath dnldfile
  70.    addfilename dnldfile HOSTDNLDFILE
  71.  
  72.    fetch aspect scriptpath nufile
  73.    addfilename nufile HOSTNUFILE
  74.  
  75.    fetch aspect scriptpath logfile
  76.    addfilename logfile HOSTLOGFILE
  77.  
  78.    fopen 0 parmfile READ TEXT
  79.    if not success
  80.       HostMsgBox("FATAL ERROR - Can't open HOST.PRM!")
  81.       ExitHost()
  82.    endif
  83.    fgets 0 welcome_msg
  84.    fgets 0 upload_path
  85.    fgets 0 dnload_path
  86.  
  87.    fgetc 0 new_usr_level
  88.       new_usr_level-=1
  89.       fgetc 0 connect_type
  90.       connect_type-=1
  91.       fgetc 0 system_type
  92.       system_type-=1
  93.       fgetc 0 goodbye_option
  94.       goodbye_option-=1
  95.    fclose 0
  96.  
  97.    save_prm()
  98.  
  99.    set aspect control off           ; turn off script button
  100.    set aspect keys on               ; we do all keys
  101.    set aspect rxdata on             ; we do all incoming data
  102.    set terminal enquiry off
  103.    set terminal statusline off
  104.    set viewgif no                   ; don't view GIF files
  105.  
  106.    set autodnld off                 ; Don't autodownload on host
  107.    set zmodem errdetect crc32       ; Use 32-bit CRC
  108.    set zmodem recvcrash protect     ; Don't let users overwrite files
  109.    set zmodem sendcrash negotiate   ; Let user recover his downloads
  110.    set zmodem timestamp off         ; Stamp files with system date/time
  111.    set zmodem txmethod streaming    ; Use fastest transmit method
  112.  
  113.    old_menu=$pwmenubar
  114.    menubar new_menu
  115.    menuitem new_menu 2 "&Disconnect user!"
  116.    showmenu new_menu
  117.    disable menu 2
  118.    showmenu new_menu
  119.    when menu call checkmenu
  120.    when userexit call ExitHost
  121. endproc
  122.  
  123. ;***********************************************************************
  124. ;*                                                                     *   
  125. ;* WAITFORCALL                                                         *
  126. ;*                                                                     *
  127. ;* This procedure waits for the modem's CD to go high and then gets    *
  128. ;* the connect message to set the baudrate.                            *
  129. ;*                                                                     * 
  130. ;* Calls: HOSTPUTS, EXITHOST                                           *
  131. ;*                                                                     *
  132. ;* Called by: MAIN                                                     *
  133. ;*                                                                     *
  134. ;* Modifies globals: connect_type, welcome_msg, tempkey, _time, _date, *
  135. ;*                   name, ontime, offtime, status, local_logon, sysop *
  136. ;*                                                                     *
  137. ;* Notes:  If connection is a direct connect it puts out the welcome   *
  138. ;*         message and returns.                                        *
  139. ;*                                                                     *
  140. ;***********************************************************************
  141. proc WaitForCall
  142. string c300, c1200, c2400, c4800, c9600, c19200, c38400, c57600
  143. string modemmsg=""
  144. integer char, index=0
  145. string auto_ans_on
  146. integer adjustbaud 
  147. long ltime, modem_speed
  148.  
  149.    fetch modem cnct300 c300
  150.    strreplace c300 "^M" "`r"           ; replace ^M with a real CR
  151.    fetch modem cnct1200 c1200
  152.    fetch modem cnct2400 c2400
  153.    fetch modem cnct4800 c4800
  154.    fetch modem cnct9600 c9600
  155.    fetch modem cnct19200 c19200
  156.    fetch modem cnct38400 c38400
  157.    fetch modem cnct57600 c57600
  158.    fetch modem autobaud adjustbaud
  159.  
  160.    clear                               ; clear screen
  161.    if connect_type==DIRECT_CON         ; check for DIRECT connect
  162.       rxflush                          ; flush receive buffer
  163.       HostPutS("`r`n")
  164.       HostPutS(welcome_msg)            ; display welcome message
  165.       HostPutS("`r`n`r`n")
  166.       return
  167.    endif
  168.  
  169.    fetch modem baudrate modem_speed
  170.    fetch modem autobaud adjustbaud     ; find out if modem's autobaud is on
  171.    fetch modem autoanson auto_ans_on   ; get modem auto answer string
  172.  
  173.    if $CARRIER                         ; if CD is high try to hangup
  174.       sdlgmsgbox "Host Message" "The modem is reporting `"ONLINE`".`n`nStart Host Mode script anyway?" STOP YESNO tempkey 2 beep
  175.       if tempkey==7
  176.          ExitHost()
  177.       endif
  178.    endif
  179.  
  180.    rxflush                             ; flush receive buffer
  181.   
  182.    set aspect rxdata on    ; aspect will process all incoming data        
  183.  
  184.  
  185.    if ! $CARRIER
  186.       dialogbox 42 25 200 70 14 "Host Mode"
  187.          text 13 25 166 8 center "Initializing Modem ...... Please Wait."
  188.       enddialog
  189.       set txpace 50
  190.       set baudrate modem_speed
  191.       transmit "~^M~"
  192.       txflush
  193.       rxflush
  194.       transmit auto_ans_on
  195.       if not waitfor "OK" 5
  196.          statmsg "Modem did not respond `"OK`" to Auto Answer command."
  197.       endif
  198.       set txpace 0
  199.       destroydlg                       ; get rid of dialog box
  200.  
  201.       _time=$TIME                      ; get current date and time
  202.       _date=$DATE
  203.  
  204.       strcmp name ""                   ; see if there was a
  205.       if success                       ; previous caller
  206.          name = "None"
  207.       endif
  208.  
  209.       dialogbox 48 4 162 172 14 "Host Mode - Waiting for call"
  210.          vtext 25 100 49 9 left _time
  211.          text  13 24 40 8 left "Last Caller: "
  212.          vtext 56 24 83 9 left name
  213.          vtext 82 100 42 9 left _date
  214.          groupbox 15 87 124 32 "Current" shadow
  215.          text  21 44 34 8 left "Online at: "
  216.          text  22 60 38 8 left "Offline at: "
  217.          vtext 76 44 39 9 left ontime
  218.          vtext 77 60 39 9 left offtime
  219.          pushbutton 16 135 54 14 "E&xit" update
  220.          pushbutton 80 135 54 14 "&Local Logon" update
  221.          groupbox 6 8 143 70 "Statistics" shadow
  222.       enddialog
  223.  
  224.       status=$DIALOG                   ; dialog box status
  225.       while 1
  226.          ltime=$LTIME
  227.          _time=$TIME
  228.          _date=$DATE
  229.  
  230.          if $carrier                   ; loop until CD goes high
  231.             exitwhile
  232.          endif
  233.  
  234.          if $KEYHIT
  235.             keyget tempkey
  236.             if tempkey==0x409           ; ALT-TAB   ;  these special keys must be
  237.                termvkey 0x409
  238.             endif
  239.          endif
  240.  
  241.          switch status
  242.             case 30
  243.                ExitHost()
  244.             endcase
  245.  
  246.             case 31
  247.                local_logon=TRUE
  248.                connect_type=DIRECT_CON
  249.                sdlgmsgbox "Host Message" "Do you want to logon as SYSOP?" QUESTION YESNO tempkey 1 beep                
  250.                if tempkey==6
  251.                   sysop=TRUE 
  252.                endif    
  253.                HostPutS("`r`n`r`n")
  254.                HostPutS(welcome_msg)   ; display welcome message
  255.                HostPutS("`r`n")
  256.                destroydlg
  257.                return
  258.             endcase        
  259.          endswitch
  260.          status=$DIALOG
  261.         
  262.          if ltime<$LTIME               ; see if time has passed
  263.             updatedlg 64               ; if it has update the dialog box
  264.          endif
  265.       endwhile
  266.  
  267.       statmsg " "
  268.       destroydlg              ; remove dialog box
  269.    
  270.       if adjustbaud           ; if autobaud detect if on
  271.          ltime=$LTIME         ; get current time
  272.          ltime+=25            ; wait for 25 seconds for a modem message
  273.  
  274.          while 1              ; loop and parse modem message
  275.          
  276.             if $LTIME >= ltime  ; if 25 seconds have passed, exit loop
  277.                statmsg "No matching connect message!" BEEP
  278.                exitwhile
  279.             endif
  280.  
  281.             if ! $RXCOUNT     ; if there are no characters
  282.                loopwhile      ; in the buffer then loop
  283.             endif
  284.       
  285.             comgetc char      ; get a characters
  286.       
  287.             if char==-1       ; if there is not a character
  288.                loopwhile      ; then loop
  289.             endif
  290.             
  291.             strpoke modemmsg index char  ; insert a character   
  292.             index++                      ; increment index
  293.             if index == 254
  294.                statmsg "No matching connect message!" BEEP
  295.                exitwhile
  296.             endif
  297.       
  298.             if strfind modemmsg c300        ; search for connect messages
  299.                statmsg "CONNECT 300"        ; this is ugly, but there's no
  300.                set baudrate 300             ; other way to do it.
  301.                exitwhile                   
  302.             elseif strfind modemmsg c1200 
  303.                statmsg "CONNECT 1200"
  304.                set baudrate 1200
  305.                exitwhile
  306.             elseif strfind modemmsg c2400 
  307.                statmsg "CONNECT 2400"   
  308.                set baudrate 2400
  309.                exitwhile
  310.             elseif strfind modemmsg c4800 
  311.                statmsg "CONNECT 4800"   
  312.                set baudrate 4800
  313.                exitwhile
  314.             elseif strfind modemmsg c9600      
  315.                statmsg "%s" modemmsg
  316.                statmsg "CONNECT 9600"
  317.                set baudrate 9600
  318.                exitwhile
  319.             elseif strfind modemmsg c19200     
  320.                statmsg "CONNECT 19200"
  321.                set baudrate 19200
  322.                exitwhile
  323.             elseif strfind modemmsg c38400 
  324.                statmsg "CONNECT 38400" 
  325.                set baudrate 38400
  326.                exitwhile
  327.             elseif strfind modemmsg c57600 
  328.                statmsg "CONNECT 57600" 
  329.                set baudrate 57600
  330.                exitwhile
  331.             endif  
  332.          endwhile
  333.       else
  334.          statmsg "Connected!"
  335.       endif      
  336.    endif
  337.    pause 1                    ; pause a moment, then flush the
  338.    rxflush                    ; buffers to remove any wierd modem
  339.    txflush                    ; message or handshake characters
  340.    HostPutS("`r`n`r`n")
  341.    HostPutS(welcome_msg)      ; display welcome message
  342.    HostPutS("`r`n")
  343. endproc
  344.  
  345. ;***********************************************************************
  346. ;*                                                                     *   
  347. ;* GETUSER                                                             *
  348. ;*                                                                     *
  349. ;* This procedure prompts a user to login.                             *
  350. ;*                                                                     *
  351. ;*                                                                     * 
  352. ;* Calls: XKEYGET, HOSTLOG, SETFAILURE, GETUSERNAME, GETUSERPSWD,      *
  353. ;*        PARSEUSRREC, SETSUCCESS                                      *
  354. ;*                                                                     *
  355. ;* Modifies globals: tempkey, connect_type, ontime                     *
  356. ;*                                                                     *
  357. ;***********************************************************************
  358. proc GetUser
  359.  
  360.    while 1
  361.       if $keyhit
  362.          XKeyGet(&tempkey)
  363.       endif
  364.  
  365.       if (! $carrier) && (connect_type==MODEM_CON)
  366.          HostLog("Lost Carrier", "")
  367.          SetFailure()
  368.          return
  369.       endif
  370.  
  371.       GetUserName()              ; Get the users name
  372.       if success
  373.          GetUserPswd()           ; Get the users password
  374.          if success
  375.             ParseUsrRec()        ; strfind and parse user record
  376.             if success           ; If found and parsed
  377.                time ontime       ; get current time
  378.                SetSuccess()
  379.                return
  380.             else
  381.                SetFailure()      ; Error getting user record
  382.                return
  383.             endif
  384.          else
  385.             SetFailure()         ; Error getting password
  386.             return
  387.          endif
  388.       else                       ; Error getting user name
  389.          SetFailure()
  390.          return
  391.       endif
  392.    endwhile
  393. endproc
  394.  
  395. ;***********************************************************************
  396. ;*                                                                     *   
  397. ;* GETUSERNAME                                                         *
  398. ;*                                                                     *
  399. ;* This procedure get the first and last name from the remote user.    *
  400. ;*                                                                     *
  401. ;*                                                                     * 
  402. ;* Calls: HOSTLOG, SETFAILURE, HOSTPUTS, HOSTGETS, HOSTGETYN,          *
  403. ;*        HOSTHANGUP                                                   *
  404. ;*                                                                     *
  405. ;* Modifies globals: connect_type, first, last, name                   *
  406. ;*                                                                     *
  407. ;***********************************************************************
  408. proc GetUserName
  409. integer i, len, tries
  410.  
  411.    tries = 0
  412.  
  413.    if (! $carrier) && (connect_type==MODEM_CON)
  414.       HostLog("Lost Carrier", "")
  415.       SetFailure()
  416.       return
  417.    endif
  418.  
  419.    pause 1
  420.    rxflush
  421.    while tries < 3
  422.       tries++
  423.       HostPutS("`r`n`r`nFirst name: ")
  424.       HostGetS(&first, NAMEMAX, DISP)  ; Get first (and optionally last)
  425.       if not success                   ; return FAILURE if CD drops
  426.          exitwhile
  427.       endif
  428.       strlen first len              ; len = length of first name
  429.       if len == 0                   ; If length is zero
  430.          loopwhile                  ;  go to top of loop
  431.       endif
  432.  
  433.       strfind first " " i           ; Is there a last name? (SPACE)
  434.       if not found
  435.          strfind first ";" i        ; (Look for SEMICOLON if no SPACE)
  436.       endif
  437.  
  438.       if found                      ; YES, there is a last name:
  439.          strpoke first i 0          ;   terminate the first name
  440.          i++                        ;   i -> 1st character in last name
  441.          substr last first i 80     ;    ulast is last name
  442.       else
  443.          HostPutS("`r`nLast name: ")
  444.          HostGetS(&last, NAMEMAX, DISP)     ; Get last name
  445.          if not success
  446.             exitwhile
  447.          endif
  448.  
  449.          strlen last len
  450.          if len == 0
  451.             loopwhile
  452.          endif
  453.       endif
  454.  
  455.       strupr first
  456.       strupr last
  457.       name = first
  458.       strcmp last ""
  459.       if not success
  460.          strcat name " "
  461.          strcat name last
  462.       endif
  463.       HostPutS("`r`n")
  464.       HostPutS(name)
  465.       HostPutS("`r`nIs this correct (Y/N)? ")
  466.       HostGetYN()
  467.       if success
  468.          return
  469.       else                          ; if user says NO
  470.          tries--                    ;   don't count it as a try
  471.       endif
  472.    endwhile
  473.    if connect_type==MODEM_CON
  474.       HostHangup()
  475.    endif
  476.    HostLog("unknown caller", "failed to enter name.")
  477.    SetFailure()
  478. endproc
  479.  
  480. ;***********************************************************************
  481. ;*                                                                     *   
  482. ;* GETUSERPSWD                                                         *
  483. ;*                                                                     *
  484. ;* This procedure get the users password.                              *
  485. ;*                                                                     *
  486. ;*                                                                     * 
  487. ;* Calls: HOSTPUTS, HOSTLOG, SETFAILURE, HOSTGETS, SETSUCCESS,         *
  488. ;*        HOSTHANGUP                                                   *
  489. ;*                                                                     *
  490. ;* Modifies globals: connect_type, passwrd, name                       *
  491. ;*                                                                     *
  492. ;***********************************************************************
  493. proc GetUserPswd
  494. integer i, tries
  495.  
  496.    tries = 0
  497.    HostPutS("`r`n")
  498.    while tries < 3
  499.       if (! $carrier) && (connect_type==MODEM_CON)
  500.          HostLog("Lost Carrier", "")
  501.          SetFailure()
  502.          return
  503.       endif
  504.  
  505.       HostPutS("`r`nPassword: ")
  506.       HostGetS(&passwrd, PSWDMAX, MASK)    ; Get passwrd
  507.       if not success
  508.          exitwhile
  509.       endif
  510.       strlen passwrd i
  511.       if i > 0
  512.          strupr passwrd
  513.          SetSuccess()
  514.          return
  515.       endif
  516.       tries++
  517.    endwhile
  518.    if connect_type==MODEM_CON
  519.       HostHangup()
  520.    endif
  521.    HostLog(name, "failed to enter password.")
  522.    SetFailure()
  523. endproc
  524.  
  525. ;***********************************************************************
  526. ;*                                                                     *   
  527. ;* HOSTGETS                                                            *
  528. ;*                                                                     *
  529. ;* This procedure gets a string from the remote user.                  *
  530. ;*                                                                     *
  531. ;*                                                                     * 
  532. ;* Calls: HOSTGETC, SETSUCCESS, HOSTPUTS                               *
  533. ;*                                                                     *
  534. ;* Modifies globals: none                                              *
  535. ;*                                                                     *
  536. ;***********************************************************************
  537. proc HostGetS
  538. strparm s
  539. intparm max, dodisp
  540. integer i
  541. string response
  542.  
  543.    strpoke s 0 0
  544.    i = 0
  545.    while 1
  546.       HostGetC(&response)
  547.       if not success
  548.          exitwhile
  549.       endif
  550.       switch response
  551.          case "`r"
  552.             SetSuccess()
  553.             exitwhile
  554.          endcase
  555.          case "`b"
  556.             if i != 0
  557.                HostPutS(response)
  558.                i--
  559.                strpoke s i 0
  560.             endif
  561.          endcase
  562.          case " "                   ; This SPACE case must immediately
  563.             if i == 0               ; precede the default so it will
  564.                loopwhile            ; fall through
  565.             endif
  566.          default
  567.             if i < max
  568.                if dodisp
  569.                   HostPutS(response)
  570.                else
  571.                   HostPutS("*")
  572.                endif
  573.                strcat s response
  574.                i++
  575.             endif
  576.          endcase
  577.       endswitch
  578.    endwhile
  579. endproc
  580.  
  581. ;***********************************************************************
  582. ;*                                                                     *
  583. ;* HOSTGETYN                                                           *
  584. ;*                                                                     *
  585. ;* This procedure get a Y or N from the remote user.                   *
  586. ;*                                                                     *
  587. ;*                                                                     * 
  588. ;* Calls: HOSTGETC, HOSTPUTS, SETSUCCESS, SETFAILURE                   *
  589. ;*                                                                     *
  590. ;* Modifies globals: none                                              *
  591. ;*                                                                     *
  592. ;***********************************************************************
  593. proc HostGetYN
  594. string response
  595.  
  596.    while 1
  597.       HostGetC(&response)
  598.       if not success
  599.          return
  600.       endif
  601.       strupr response
  602.       HostPutS(response)
  603.       switch response
  604.          case "Y"
  605.             SetSuccess()
  606.             return
  607.          endcase
  608.          case "N"
  609.          default
  610.             SetFailure()
  611.             return
  612.          endcase
  613.       endswitch
  614.    endwhile
  615. endproc
  616.  
  617. ;***********************************************************************
  618. ;*                                                                     *   
  619. ;* HOSTGETC                                                            *
  620. ;*                                                                     *
  621. ;* This procedure gets a character from the remote user.               *
  622. ;*                                                                     *
  623. ;*                                                                     * 
  624. ;* Calls: XKEYGET, HOSTLOG, SETFAILURE, SETSUCCESS                     *
  625. ;*                                                                     *
  626. ;* Modifies globals: local_logon, connect_type                         *
  627. ;*                                                                     *
  628. ;***********************************************************************
  629. proc HostGetC
  630. strparm c
  631. integer i = -1
  632.  
  633.    while i == -1
  634.       if $keyhit              ; If a key is pressed
  635.          XKeyGet(&i)          ;   get the key
  636.       endif
  637.       if !local_logon
  638.          if $RXDATA           ; If data available at port
  639.             comgetc i         ; get the next character
  640.          endif
  641.          if (! $carrier) && (connect_type==MODEM_CON)  ; If carrier drops
  642.             HostLog("Lost Carrier", "")
  643.             SetFailure()      ;    set error return code
  644.             return            ;    and return to caller
  645.          endif
  646.       endif
  647.    endwhile
  648.    strfmt c "%c" i
  649.    SetSuccess()
  650. endproc
  651.  
  652. ;***********************************************************************
  653. ;*                                                                     *   
  654. ;* HOSTPUTS                                                            *
  655. ;*                                                                     *
  656. ;* This procedure send a string to the remote user and displays it     *
  657. ;* in the terminal window.                                             *
  658. ;*                                                                     * 
  659. ;* Calls: NONE                                                         *
  660. ;*                                                                     *
  661. ;* Called by: EVERYTHING!! 168 times                                   *
  662. ;*                                                                     *
  663. ;* Modifies globals: local_logon                                       *
  664. ;*                                                                     *
  665. ;***********************************************************************
  666. proc HostPutS
  667. strparm s
  668.  
  669.    if !local_logon
  670.       transmit s        ; send the string to the remote user
  671.    endif
  672.    termwrites s         ; send the string to the local screen
  673. endproc
  674.  
  675. ;***********************************************************************
  676. ;*                                                                     *   
  677. ;* PARSEUSRREC                                                         *
  678. ;*                                                                     *
  679. ;* This procedure looks up a user in .USR file and parse record        *
  680. ;* into globals.                                                       *
  681. ;*                                                                     *
  682. ;*                                                                     * 
  683. ;* Calls: ADDUSER, COPYSFLD, SETSUCCESS, GETUSERPSWD,  HOSTPUTS,       *
  684. ;*        HOSTHANGUP, HOSTLOG, SETFAILURE, HOSTMSGBOX                  *
  685. ;*                                                                     *
  686. ;* Modifies globals: name, first, last, passwrd, usrfile, record,      *
  687. ;*                   access_level, remarks, connect_type, system_type  *
  688. ;*                                                                     *
  689. ;* NOTES:                                                              *
  690. ;*        access_level  - User's access level ("0", "1", or "2")       *
  691. ;*             comment  - User's comment field                         *
  692. ;*             first    - User's first name                            *
  693. ;*             last     - User's last name                             *
  694. ;*             name     - User's full name (first and last)            *
  695. ;*             passwrd  - User's password                              *
  696. ;*             record   - Raw record (terminated with a line feed)     *
  697. ;*                                                                     *
  698. ;*             HOSTS.USR record:                                       *
  699. ;*                                                                     *
  700. ;*                 lastname;firstname;passwrd;n;comment.......         *
  701. ;*                 (n is the access_level level {'0','1',or '2'})      *
  702. ;*                                                                     *
  703. ;***********************************************************************
  704. proc ParseUsrRec
  705. integer i, tries=1
  706. string tmp, tmp1, tmp2, tmp3
  707.  
  708.    strfind name " " i               ; i = index of blank name separator
  709.    if found
  710.       strcpy first name i           ; copy first name
  711.       i++                           ; i = index of last name
  712.       substr last name i 79         ; extract last name
  713.    endif
  714.    strfmt tmp "%s;%s" last first    ; 'tmp' is what we're looking for
  715.    strfmt tmp2 "%s;%s;%s" last first passwrd
  716.    strlen tmp i                     ; i = length of name part
  717.    isfile usrfile
  718.    if not success
  719.       AddUser()
  720.       return
  721.    else
  722.       fopen 1 usrfile READ TEXT     ; Try to open user file
  723.    endif
  724.    if success                       ; If opened
  725.       while not FEOF 1              ;    loop until end of file
  726.          fgets 1 record             ;       Get record
  727.          strupr record              ; upper case the record
  728.          strcmp record tmp i        ;       Scan record for user
  729.          if success                 ;       If this is our guy,
  730.             while tries<3
  731.                strextract tmp3 record ";" 2
  732.                strfmt tmp1 "%s;%s" tmp tmp3
  733.                strlen tmp1 i
  734.                strcmp record tmp2 i
  735.                if success
  736.                   ; Copy password
  737.                   CopySFld(&passwrd, record, &i, FLD_SEP)      
  738.  
  739.                   ; Copy access level level
  740.                   CopySFld(&access_level, record, &i, FLD_SEP) 
  741.  
  742.                   ; Copy comment
  743.                   CopySFld(&remarks, record, &i, FLD_SEP)
  744.  
  745.                   SetSuccess()
  746.                   return
  747.                else
  748.                   GetUserPswd()
  749.                   if success
  750.                      strfmt tmp2 "%s;%s;%s" last first passwrd
  751.                   endif
  752.                   tries++
  753.                endif
  754.             endwhile
  755.             HostPutS("`r`n`r`nPassword incorrect.`r`n")
  756.             if connect_type==MODEM_CON
  757.                HostHangup()
  758.             endif
  759.             HostLog(name, "failed password check.")
  760.             SetFailure()
  761.             return
  762.          endif
  763.       endwhile
  764.       fclose 1
  765.       if system_type==CLOSED_SYSTEM
  766.          HostPutS("`r`nSorry, this is a closed system.`r`n")
  767.          if connect_type==MODEM_CON
  768.             HostHangup();
  769.          endif
  770.          HostLog(name, "attempted to login to closed system.")
  771.          SetFailure()
  772.          return
  773.       endif
  774.       AddUser()
  775.       return
  776.    else
  777.       HostMsgBox("ERROR - Can't open HOST.USR file!")
  778.    endif
  779.    SetFailure()
  780. endproc
  781.  
  782. ;***********************************************************************
  783. ;*                                                                     *
  784. ;*  COPYSFLD                                                           *
  785. ;*                                                                     *
  786. ;*  This procedure will copy a string field (SFLD) from any position   *
  787. ;*  within the source string, to the destination string.  Also, it     *
  788. ;*  will increment the index by the length of the field copied.        *
  789. ;*                                                                     *
  790. ;* Calls: NONE                                                         *
  791. ;*                                                                     *
  792. ;* Modifies globals: none                                              *
  793. ;*                                                                     *
  794. ;* NOTES:                                                              *
  795. ;* Input:  (&destination,source,&index,field_separator)                *
  796. ;*                                                                     *
  797. ;* Return:  destination and int are updated.                           *
  798. ;*                                                                     *
  799. ;* Notes:  Terminates when a field_separator or line feed is           *
  800. ;*         encountered. If neither is encountered, the rest of the     *
  801. ;*          field is copied.                                           *
  802. ;*                                                                     *
  803. ;***********************************************************************
  804. proc CopySFld
  805. strparm dst
  806. strparm src
  807. intparm index
  808. intparm fldsep
  809. integer newidx
  810. string endstr,tmp
  811.  
  812.    substr endstr src index 79          ; copy end of string to local var
  813.    strfmt tmp "%c" fldsep              ; tmp = field separator as a string
  814.    strfind endstr tmp newidx           ; see if a separator is in the string
  815.    if not found                        ; If separator not found:
  816.       strfind endstr "\n" newidx       ;   is a line feed in the string?
  817.       if not found                     ; If not:
  818.          strlen endstr newidx          ;   use the whole string
  819.       endif
  820.    endif
  821.    strcpy dst endstr newidx            ; copy field
  822.    index = index + newidx + 1          ; set caller's index
  823. endproc
  824.  
  825. ;***********************************************************************
  826. ;*                                                                     *   
  827. ;* HOSTHANGUP                                                          *
  828. ;*                                                                     *
  829. ;* This procedure attempts to hangup the line several times.           *
  830. ;*                                                                     *
  831. ;*                                                                     * 
  832. ;* Calls: HOSTPUTS, TXWAIT                                             *
  833. ;*                                                                     *
  834. ;* Modifies globals: none                                              *
  835. ;*                                                                     *
  836. ;***********************************************************************
  837. proc HostHangup
  838. integer hanguptries=3
  839.  
  840.    while $TXCOUNT>0        ; wait for tx buffer to clear
  841.    endwhile
  842.    if not $carrier
  843.       return
  844.    endif
  845.    while hanguptries--
  846.       pause 1
  847.       hangup
  848.       if not $carrier
  849.          exitwhile
  850.       endif
  851.    endwhile
  852.    if $carrier
  853.       HostPutS ("`r`nERROR - Unable to hangup.`r`n")
  854.    endif
  855. endproc
  856.  
  857. ;***********************************************************************
  858. ;*                                                                     *   
  859. ;* SETFAILURE                                                          *
  860. ;*                                                                     *
  861. ;* This procedure sets the IF FAILURE flag to TRUE.                    *
  862. ;*                                                                     *
  863. ;*                                                                     * 
  864. ;* Calls: NONE                                                         *
  865. ;*                                                                     *
  866. ;* Modifies globals: none                                              *
  867. ;*                                                                     *
  868. ;***********************************************************************
  869. proc SetFailure
  870.    strcmp "X" "Y"                      ; compare is always FALSE
  871. endproc
  872.  
  873. ;***********************************************************************
  874. ;*                                                                     *   
  875. ;* SETSUCCESS                                                          *
  876. ;*                                                                     *
  877. ;* This procedure sets the IF SUCCESS flag to TRUE.                    *
  878. ;*                                                                     *
  879. ;*                                                                     * 
  880. ;* Calls: NONE                                                         *
  881. ;*                                                                     *
  882. ;* Modifies globals: none                                              *
  883. ;*                                                                     *
  884. ;***********************************************************************
  885. proc SetSuccess
  886.    strcmp "X" "X"                       ; compare is always TRUE
  887. endproc
  888.  
  889. ;***********************************************************************
  890. ;*                                                                     *   
  891. ;* XKEYGET                                                             *
  892. ;*                                                                     *
  893. ;* This procedure processes local keystrokes.                          *
  894. ;*                                                                     *
  895. ;*                                                                     * 
  896. ;* Calls: EXITHOST, HOSTHANGUP                                         *
  897. ;*                                                                     *
  898. ;* Modifies globals: none                                              *
  899. ;*                                                                     *
  900. ;***********************************************************************
  901. proc xkeyget
  902. intparm key
  903. integer real_key
  904.    
  905.    keyget key              ; get the key value
  906.    switch key
  907.       
  908.       case 0x409           ; ALT-TAB   ;  these special keys must be
  909.       case 0x14            ; CAPS LOCK ;  must be passed to the
  910.       case 0x890           ; NUM LOCK  ;  main window to be recognized
  911.          termkey key
  912.          key=0x00
  913.       endcase
  914.  
  915.       case 0x458           ; E&xit Host
  916.       case 0x558
  917.          ExitHost()
  918.       endcase
  919.  
  920.       case 0x444
  921.       case 0x544           ; &Disconnect User
  922.          HostHangup()
  923.          longjmp 1 1
  924.       endcase
  925.  
  926.       case 0x452
  927.       case 0x552
  928.          longjmp 1 1       ; &Recycle host
  929.       endcase
  930.  
  931.       default
  932.          keytoascii key real_key    ; convert virtual key into
  933.          key=real_key               ; ASCII value for return
  934.       endcase
  935.    endswitch
  936. endproc
  937.  
  938. ;***********************************************************************
  939. ;*                                                                     *   
  940. ;* GETNEWPSWD                                                          *
  941. ;*                                                                     *
  942. ;* This procedure gets the password for a new user.                    *
  943. ;*                                                                     *
  944. ;*                                                                     * 
  945. ;* Calls: HOSTPUTS, HOSTGETS, SETSUCCESS, HOSTHANGUP, HOSTLOG,         *
  946. ;*        SETFAILURE                                                   *
  947. ;*                                                                     *
  948. ;* Modifies globals: passwrd, connect_type, name                       *
  949. ;*                                                                     *
  950. ;***********************************************************************
  951. proc GetNewPswd
  952.  
  953. integer i, tries
  954. string newpswd
  955.  
  956.    tries = 0
  957.    HostPutS("`r`n")
  958.    while tries < 3
  959.       HostPutS("`r`nPlease verify: ")
  960.       HostGetS(&newpswd, PSWDMAX, MASK)    ; Get passwrd
  961.       if not success
  962.          exitwhile
  963.       endif
  964.       strlen passwrd i
  965.       if i > 0
  966.          strupr passwrd
  967.          strupr newpswd
  968.          strcmp passwrd newpswd
  969.          if success
  970.             SetSuccess()
  971.             return
  972.          endif
  973.       endif
  974.       tries++
  975.    endwhile
  976.    if connect_type==MODEM_CON
  977.       HostHangup()
  978.    endif
  979.    HostLog(name, "failed to verify password.")
  980.    SetFailure()
  981. endproc
  982.  
  983. ;***********************************************************************
  984. ;*                                                                     *   
  985. ;* ADDUSER                                                             *
  986. ;*                                                                     *
  987. ;* This procedure adds a new user the the HOST.USR file.               *
  988. ;*                                                                     * 
  989. ;* Calls: GETNEWPSWD, HOSTMSGBOX, DISPLAYFILE, HOSTLOG, SETSUCCESS,    *
  990. ;*        SETFAILURE                                                   *
  991. ;*                                                                     *
  992. ;* Modifies globals: usrfile, record, last, first, passwrd,            *
  993. ;*                   new_usr_level, access_level, name                 *
  994. ;*                                                                     *
  995. ;***********************************************************************
  996. proc AddUser
  997.  
  998.    GetNewPswd()
  999.    if success
  1000.       isfile usrfile
  1001.       if not success
  1002.          fopen 1 usrfile CREATE TEXT
  1003.          if not success
  1004.             HostMsgBox("ERROR - Can't create HOST.USR file!")
  1005.             ExitHost()
  1006.          endif
  1007.       else
  1008.          fopen 1 usrfile WRITE TEXT
  1009.          if not success
  1010.             HostMsgBox("ERROR - Can't open HOST.USR file!")
  1011.             ExitHost()
  1012.          endif
  1013.          fseek 1 0 2   ; go to end of file
  1014.       endif
  1015.       strfmt record "%s;%s;%s;%i;* NEW USER *" last first passwrd new_usr_level
  1016.       itoa new_usr_level access_level
  1017.       fputs 1 record
  1018.  
  1019.       if not success
  1020.          HostMsgBox("ERROR - Didn't write user info!")
  1021.       endif
  1022.  
  1023.       fclose 1
  1024.       DisplayFile(nufile, 23)
  1025.       HostLog(name, "first login - added to user file.")
  1026.       SetSuccess()
  1027.       return
  1028.    endif
  1029.    SetFailure()
  1030. endproc
  1031.  
  1032. ;***********************************************************************
  1033. ;*                                                                     *   
  1034. ;* CHECKMENU                                                           *
  1035. ;*                                                                     *
  1036. ;* This procedure processes menu selections made with the mouse.       *
  1037. ;*                                                                     *
  1038. ;*                                                                     * 
  1039. ;* Calls: HOSTHANGUP, EXITHOST                                         *
  1040. ;*                                                                     *
  1041. ;* Called by: WHEN MENU command                                        *
  1042. ;*                                                                     *
  1043. ;* Modifies globals: status                                            *
  1044. ;*                                                                     *
  1045. ;***********************************************************************
  1046. proc CheckMenu
  1047.  
  1048.    status=$MENU
  1049.    switch status
  1050.       case 2               ; 2 is &Disconnect remote
  1051.          HostHangup()
  1052.          longjmp 1 1
  1053.       endcase
  1054.       case 3
  1055.          longjmp 1 1       ; 3 &Recycle host
  1056.       endcase
  1057.       case 4
  1058.          ExitHost()
  1059.       endcase
  1060.    endswitch
  1061. endproc
  1062.  
  1063. ;***********************************************************************
  1064. ;*                                                                     *   
  1065. ;* EXITHOST                                                            *
  1066. ;*                                                                     *
  1067. ;* This procedure allows safe shutdown of Host Mode script.            *
  1068. ;*                                                                     *
  1069. ;*                                                                     * 
  1070. ;* Calls: HOSTHANGUP, HOSTMSGBOX, HOSTLOG, RESTORE_PRM                 *
  1071. ;*                                                                     *
  1072. ;* Modifies globals: connect_type, action_status, meta_status,         *
  1073. ;*                   dial_status,  setup_status                        *
  1074. ;*                                                                     *
  1075. ;***********************************************************************
  1076. proc ExitHost
  1077. string auto_ans_off
  1078. integer response
  1079.  
  1080.    if (connect_type==MODEM_CON) || (local_logon==TRUE)
  1081.  
  1082.       rxflush
  1083.       txflush
  1084.       transmit "^M"
  1085.       statmsg "Closing Host Mode ..." BEEP
  1086.       set txpace 50
  1087.       if $CARRIER
  1088.          sdlgmsgbox "Host Message" "Hangup Line?" QUESTION YESNO response 2 BEEP
  1089.          if response==6
  1090.             HostHangup()
  1091.             fetch modem autoansoff auto_ans_off
  1092.             pause 1
  1093.             transmit auto_ans_off
  1094.             waitfor "OK" 8
  1095.          endif
  1096.       else
  1097.          fetch modem autoansoff auto_ans_off
  1098.          pause 1
  1099.          transmit auto_ans_off
  1100.          waitfor "OK" 8
  1101.       endif
  1102.    endif
  1103.    HostMsgBox("Host Mode aborted")
  1104.    HostLog("Host mode offline.", "")
  1105.    restore_prm()
  1106.    if action_status
  1107.       actionbar on
  1108.    endif
  1109.    if meta_status
  1110.       metakeys on
  1111.    endif
  1112.    if dial_status
  1113.       dialdir on
  1114.    endif
  1115.    if setup_status
  1116.       setup on
  1117.    endif
  1118.    statmsg " "
  1119.    pwtitlebar "PROCOMM PLUS for Windows"
  1120.    clear
  1121.    halt
  1122. endproc
  1123.  
  1124. ;***********************************************************************
  1125. ;*                                                                     *   
  1126. ;* DISPLAYFILE                                                         *
  1127. ;*                                                                     *
  1128. ;* This procedure sends an ASCII file to the remote user with paging.  *
  1129. ;*                                                                     *
  1130. ;*                                                                     * 
  1131. ;* Calls: SETFAILURE, HOSTPUTS, HOSTGETC, SETSUCCESS                   *
  1132. ;*                                                                     *
  1133. ;* Modifies globals: none                                              *
  1134. ;*                                                                     *
  1135. ;***********************************************************************
  1136. proc DisplayFile
  1137. strparm _file              ; file to transmit
  1138. intparm page_length        ; how many lines before -MORE- prompt
  1139. string line, response
  1140. integer count=0
  1141.  
  1142.    isfile _file            ; check for the file
  1143.    if not success          ; if it doesn't exist
  1144.       SetFailure()         ; return
  1145.       return
  1146.    endif
  1147.    fopen 5 _file READ      ; open the file
  1148.    while 1                 ; loop forever
  1149.       if not $CARRIER
  1150.          fclose 5
  1151.          SetFailure()
  1152.          return
  1153.       endif
  1154.       fgets 5 line         ; get a line
  1155.       if FEOF 5            ; check for EOF
  1156.          exitwhile
  1157.       endif
  1158.       HostPutS(line)          ; display line
  1159.       inc count               ; increment line counter
  1160.       if count==page_length   ; if count == page length display a prompt
  1161.          HostPutS("-MORE-")
  1162.          HostGetC(&response)  ; get user input
  1163.          HostPutS("`b`b`b`b`b`b")
  1164.          strupr response
  1165.          strcmp response "N"  ; if the user says NO then
  1166.          if success
  1167.             exitwhile
  1168.          endif
  1169.          count=1              ; reset line counter
  1170.       endif
  1171.    endwhile
  1172.    fclose 5                  ; close the file
  1173.    SetSuccess()
  1174. endproc
  1175.  
  1176. ;***********************************************************************
  1177. ;*                                                                     *   
  1178. ;* HOSTMSGBOX                                                          *
  1179. ;*                                                                     *
  1180. ;* This procedure displays a dialog box with an error message for      *
  1181. ;* 3 seconds.                                                          *
  1182. ;*                                                                     * 
  1183. ;* Calls: NONE                                                         *
  1184. ;*                                                                     *
  1185. ;* Modifies globals: message                                           *
  1186. ;*                                                                     *
  1187. ;***********************************************************************
  1188. proc HostMsgBox
  1189. strparm _message
  1190.  
  1191.    beep
  1192.    beep
  1193.    mspause 500
  1194.    dialogbox 48 20 174 65 15 "Host Mode Message"
  1195.       vtext 1 16 167 26 center message
  1196.    enddialog
  1197.    message=_message
  1198.    updatedlg -1
  1199.    pause 2
  1200.    destroydlg
  1201. endproc
  1202.  
  1203. ;***********************************************************************
  1204. ;*                                                                     *   
  1205. ;* CHAT                                                                *
  1206. ;*                                                                     *
  1207. ;* This procedure allows the sysop and a remote user to converse       *
  1208. ;* online.                                                             *
  1209. ;*                                                                     *
  1210. ;*                                                                     * 
  1211. ;* Calls: HOSTPUTS, HOSTGETC, SETFAILURE                               *
  1212. ;*                                                                     *
  1213. ;* Modifies globals: msg, name, status                                 *
  1214. ;*                                                                     *
  1215. ;***********************************************************************
  1216. proc Chat
  1217. string c
  1218. long timer
  1219.  
  1220.    HostPutS("`r`nPaging Host Operator ...`r`n")
  1221.    strfmt msg "Remote user %s is requesting to chat." name
  1222.    dialogbox 26 22 200 67 13
  1223.       pushbutton 59 38 76 14 "OK" normal default
  1224.       vtext 9 13 178 9 center msg
  1225.    enddialog
  1226.    status=$DIALOG
  1227.    alarm
  1228.    alarm
  1229.    timer=$LTIME
  1230.    while ($LTIME < (timer+8))
  1231.       if status==10
  1232.          destroydlg
  1233.          HostPutS("`r`nHost Operator is online!`r`n`r`n")
  1234.          HostPutS("Press ESC to end chat.`r`n`r`n")
  1235.          while 1
  1236.             HostGetC(&c)
  1237.             if failure
  1238.                SetFailure()
  1239.                return
  1240.             endif
  1241.             switch c
  1242.                case "`r"
  1243.                   strcat c "`n"
  1244.                endcase
  1245.  
  1246.                case "`x1b"
  1247.                   return
  1248.                endcase
  1249.             endswitch
  1250.             transmit c
  1251.             termwrites c
  1252.          endwhile
  1253.       endif
  1254.       status=$DIALOG
  1255.    endwhile
  1256.    destroydlg
  1257.    HostPutS("`r`nHost Operator is not available!`r`n")
  1258. endproc
  1259.  
  1260. ;***********************************************************************
  1261. ;*                                                                     *   
  1262. ;* COUNTMSG                                                            *
  1263. ;*                                                                     *
  1264. ;* This procedure counts the number of mail messages.                  *
  1265. ;*                                                                     *
  1266. ;*                                                                     * 
  1267. ;* Calls: HOSTMSGBOX, EXITHOST                                         *
  1268. ;*                                                                     *
  1269. ;* Modifies globals: hdrfile                                           *
  1270. ;*                                                                     *
  1271. ;***********************************************************************
  1272. proc CountMsg
  1273. intparm number
  1274.  
  1275. integer dummy
  1276. string msg_entry
  1277.  
  1278.    number=0                         ; start with 0 messages
  1279.  
  1280.    isfile hdrfile                   ; is HOST.HDR present
  1281.    if not success                   ; if not return
  1282.       return
  1283.    endif
  1284.     
  1285.    fopen 4 hdrfile READ             ; open HOST.HDR
  1286.    if not success                   ; error opening the file
  1287.       HostMsgBox("FATAL ERROR - Can't open HOST.HDR file!")
  1288.       ExitHost()                    ; exit script
  1289.    endif
  1290.    while 1                          ; loop forever
  1291.       fread 4 msg_entry 128 dummy   ; read 1 message entry
  1292.       if FEOF 4                     ; if EOF, close file and return
  1293.          fclose 4
  1294.          return
  1295.       endif
  1296.       inc number                    ; otherwise add 1 to message count
  1297.    endwhile
  1298. endproc
  1299.  
  1300. ;***********************************************************************
  1301. ;*                                                                     *   
  1302. ;* MAILGETLINE                                                         *
  1303. ;*                                                                     *
  1304. ;* This procedure accepts a string from the user for entering mail.    *
  1305. ;*                                                                     *
  1306. ;*                                                                     * 
  1307. ;* Calls: HOSTGETC, SETSUCCESS, HOSTPUTS                               *
  1308. ;*                                                                     *
  1309. ;* Modifies globals: none                                              *
  1310. ;*                                                                     *
  1311. ;***********************************************************************
  1312. proc MailGetLine
  1313. strparm s
  1314. integer max=70
  1315. integer i
  1316. string response
  1317.  
  1318.    strpoke s 0 0
  1319.    i = 0
  1320.    while 1
  1321.       HostGetC(&response)
  1322.       if not success
  1323.          SetFailure()
  1324.          return
  1325.       endif
  1326.       switch response
  1327.          case "`r"
  1328.             SetSuccess()
  1329.             exitwhile
  1330.             endcase
  1331.          case "`b"
  1332.             if i != 0
  1333.                HostPutS(response)
  1334.                i--
  1335.                strpoke s i 0
  1336.             endif
  1337.             endcase
  1338.          case " "                   ; This SPACE case must immediately
  1339.             if i>55                 ; precede the DEFAULT so it will
  1340.                i=max                ; fall through
  1341.             endif                   ; do wordwrap stuff here!!!
  1342.          default
  1343.             if i == max
  1344.                HostPutS(response)
  1345.                strcat s response
  1346.                SetSuccess()
  1347.                exitwhile
  1348.             else
  1349.                HostPutS(response)
  1350.                strcat s response
  1351.                i++
  1352.             endif
  1353.          endcase
  1354.       endswitch
  1355.    endwhile
  1356. endproc
  1357.  
  1358. ;***********************************************************************
  1359. ;*                                                                     *   
  1360. ;* CHECKMAIL                                                           *
  1361. ;*                                                                     *
  1362. ;* This procedure notifies a user that there is new mail waiting.      *
  1363. ;*                                                                     *
  1364. ;*                                                                     * 
  1365. ;* Calls: HOSTPUTS                                                     *
  1366. ;*                                                                     *
  1367. ;* Modifies globals: hdrfile, _date, _time, name                       *
  1368. ;*                                                                     *
  1369. ;***********************************************************************
  1370. proc CheckMail
  1371. integer msg_num, msg_length, msg_flag, dummy
  1372. string destination, from, subject
  1373. long offset
  1374.  
  1375.    isfile hdrfile                ; is HOST.HDR present
  1376.    if not success                ; if not return
  1377.       return
  1378.    endif
  1379.  
  1380.    fopen 0 hdrfile READ          ; open HOST.HDR for read only
  1381.    if not success                ; error opening file
  1382.       return
  1383.    endif
  1384.    while 1                       ; loop forever
  1385.       fgeti 0 msg_num            ; get the message number
  1386.       if FEOF 0                  ; if EOF exit the while loop
  1387.          exitwhile
  1388.       endif
  1389.       fgetl 0 offset             ; get message file offset
  1390.       fgeti 0 msg_length         ; get length of message
  1391.       fgetc 0 msg_flag           ; get message flag
  1392.       fread 0 destination 31 dummy     ; get TO:
  1393.       fread 0 from 31 dummy            ; get FROM:
  1394.       fread 0 subject 37 dummy         ; get subject
  1395.       fread 0 _date 9 dummy            ; get message date
  1396.       fread 0 _time 11 dummy           ; get message time
  1397.       strcmp destination name          ; compare message TO: and user name
  1398.       if success                       ; if this is there message
  1399.          if (msg_flag & 2)==NEWMAIL    ; check to see if NEWMAIL flag is set
  1400.             HostPutS("`r`n`aYou have mail waiting!`r`n`r`n")
  1401.             exitwhile                  ; leave the while loop
  1402.          endif
  1403.       endif
  1404.    endwhile
  1405.    fclose 0                            ; close HOST.HDR
  1406. endproc
  1407.  
  1408. ;***********************************************************************
  1409. ;*                                                                     *   
  1410. ;* CHANGEFLAG                                                          *
  1411. ;*                                                                     *
  1412. ;* This procedure modifies the flag byte for a message.                *
  1413. ;*                                                                     *
  1414. ;*                                                                     * 
  1415. ;* Calls: NONE                                                         *
  1416. ;*                                                                     *
  1417. ;* Modifies globals: hdrfile, msg_number                               *
  1418. ;*                                                                     *
  1419. ;***********************************************************************
  1420. proc ChangeFlag
  1421. intparm flagbyte
  1422. long hdr_offset
  1423.  
  1424.    fopen 0 hdrfile WRITE               ; open HOST.HDR as write only
  1425.    if not success                      ; error opening file
  1426.       return
  1427.    endif
  1428.    hdr_offset=((msg_number-1)*128)+8
  1429.    fseek 0 hdr_offset 0                ; seek to flag byte of current message
  1430.    fputc 0 flagbyte                    ; write the passed parameter
  1431.    fclose 0                            ; close HOST.HDR
  1432. endproc
  1433.  
  1434. ;***********************************************************************
  1435. ;*                                                                     *   
  1436. ;* DELETEMSG                                                           *
  1437. ;*                                                                     *
  1438. ;* This procedure marks a mial message for deletion.                   *
  1439. ;*                                                                     *
  1440. ;*                                                                     * 
  1441. ;* Calls: HOSTMSGBOX,   HOSTPUTS,     CHANGEFLAG                       *
  1442. ;*                                                                     *
  1443. ;* Modifies globals: hdrfile, msg_number, _date, _time, name,          *
  1444. ;*                   access_level                                      *
  1445. ;*                                                                     *
  1446. ;***********************************************************************
  1447. proc DeleteMsg
  1448. integer msg_num, msg_length, msg_flag, dummy
  1449. long offset, hdr_offset
  1450. string destination, from, subject
  1451.     
  1452.    isfile hdrfile
  1453.    if not success
  1454.       return
  1455.    endif
  1456.  
  1457.    fopen 0 hdrfile READ
  1458.    if not success
  1459.       HostMsgBox("Can't open HDRFILE - Proc DeleteMsg")
  1460.       return
  1461.    endif
  1462.  
  1463.    hdr_offset=(msg_number-1)*128
  1464.    fseek 0 hdr_offset 0
  1465.  
  1466.    fgeti 0 msg_num
  1467.    if FEOF 0
  1468.       fclose 0
  1469.       return
  1470.    endif
  1471.    fgetl 0 offset                   ; get message file offset
  1472.    fgeti 0 msg_length               ; get length of message
  1473.    fgetc 0 msg_flag                 ; get message flag
  1474.    fread 0 destination 31 dummy     ; get TO:
  1475.    fread 0 from 31 dummy            ; get FROM:
  1476.    fread 0 subject 37 dummy         ; get subject
  1477.    fread 0 _date 9 dummy            ; get message date
  1478.    fread 0 _time 11 dummy           ; get message time
  1479.    strcmp destination name          ; compare message TO: and user name
  1480.    if not success
  1481.       strcmp from name              ; compare message FROM: and user name
  1482.       if not success
  1483.          strcmp access_level "2"    ; is this user a level 2 security
  1484.          if not success             ; if not send message and return
  1485.             HostPutS("`r`nYou can't delete this message.`r`n")
  1486.             return
  1487.          endif
  1488.       endif
  1489.    endif
  1490.    fclose 0                         ; close HOST.HDR
  1491.    msg_flag=msg_flag+4              ; add DELETED flag to the flag byte
  1492.    ChangeFlag(msg_flag)             ; pass new message flag to ChangeFlag
  1493.    HostPutS("`r`nMessage has been marked for deletion.`r`n`r`n")
  1494. endproc
  1495.  
  1496. ;***********************************************************************
  1497. ;*                                                                     *   
  1498. ;* TXWAIT                                                              *
  1499. ;*                                                                     *
  1500. ;* This procedure waits for the TX buffer to empty before returning.   *
  1501. ;*                                                                     *
  1502. ;*                                                                     * 
  1503. ;* Calls: NONE                                                         *
  1504. ;*                                                                     *
  1505. ;* Modifies globals: none                                              *
  1506. ;*                                                                     *
  1507. ;***********************************************************************
  1508. proc txwait
  1509.    while $TXCOUNT>0
  1510.    endwhile
  1511.    pause 3
  1512. endproc
  1513. ;**** End of SUBS.WAS ****
  1514.